package com.example.demo.controller;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;

import com.example.demo.po.Special;
import com.example.demo.po.Tv;
import com.example.demo.service.SpecialService;
import com.example.demo.service.TvService;


@Controller
@RequestMapping("/admin")
public class AdminSpecialController {
	
	@Autowired
	private SpecialService specialService;
	
	@Autowired
	private TvService tvService;
	
	
	@RequestMapping(value="/adminSpecial.action",method=RequestMethod.GET)
	public String indext(Model model){
		
		List<Tv> tvList = tvService.selectAll();
		
		model.addAttribute("tvList", tvList);
		
		
		List<Special> specialList = specialService.selectAll();
		
		model.addAttribute("specialList", specialList);
		
		return "admin/special/specialList";		
	}
	
	@RequestMapping(value="/toEditSpecial.action",method=RequestMethod.GET)
	public String toEdit(Model model,Integer id){
		
		if(id!=null){
			
			Special special=specialService.selectById(id);
			
			model.addAttribute("special", special);
		}
		
		return "admin/special/edit";
		
	}
	
	@RequestMapping(value="/editSpecial.action",method=RequestMethod.POST)
	public String edit(Special special){
		
		if(special.getId()!=null){
			specialService.update(special);
		}else{
			specialService.insert(special);
		}
		
		return "redirect:adminSpecial.action";		
	}
	
	@RequestMapping(value="deleteSpecial.action",method=RequestMethod.GET)
	public String delete(Integer id){
		
		specialService.delete(id);
		return "redirect:adminSpecial.action";
		
	}
	@RequestMapping(value="updateTvids.action",method=RequestMethod.POST)
	public String updateTvids(Integer id,String tvids,Special special){
		
	
		specialService.updateTvids(special);
		
		return "redirect:adminSpecial.action";
		
	}
	

}
